package com.example.lynandroid.views

import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import com.example.lynandroid.R
import com.example.lynandroid.enum.LifeType
import com.example.lynandroid.lifeLog

class MyGroup(context: Context, attributeSet: AttributeSet) : LinearLayout(context, attributeSet) {
    private val name = "MyGroup"


    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        log(LifeType.Measure)
    }

    override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
        super.onLayout(changed, l, t, r, b)
        log(LifeType.Layout)
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        log(LifeType.Draw)
    }

    override fun onAttachedToWindow() {
        super.onAttachedToWindow()
        log(LifeType.AttachToWindow)
    }

    override fun onWindowFocusChanged(hasWindowFocus: Boolean) {
        super.onWindowFocusChanged(hasWindowFocus)
        log(LifeType.WindowFocusChange)
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        log(LifeType.DetachFromWindow)
    }

    override fun onVisibilityChanged(changedView: View, visibility: Int) {
        super.onVisibilityChanged(changedView, visibility)
        log(LifeType.VisibleChange)
    }

    override fun onFinishInflate() {
        super.onFinishInflate()
        log(LifeType.FinishInflater)
    }

    private fun log(lifeType: LifeType) {
        lifeLog(name, lifeType)
    }
}